# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load("//bazel:pl_build_system.bzl", "pl_cc_bpf_test", "pl_cc_library", "pl_cc_test")

package(default_visibility = ["//src/stirling:__subpackages__"])

pl_cc_library(
    name = "cc_library",
    srcs = glob(
        ["*.cc"],
        exclude = [
            "**/*_test.cc",
        ],
    ),
    hdrs = glob(["*.h"]),
    deps = [
        "//src/common/exec:cc_library",
        "//src/common/fs:cc_library",
        "//src/common/metrics:cc_library",
        "//src/common/minitar:cc_library",
        "//src/common/system:cc_library",
        "//src/common/zlib:cc_library",
        "//src/stirling/upid:cc_library",
        "@com_github_tencent_rapidjson//:rapidjson",
    ],
)

pl_cc_test(
    name = "utils_test",
    srcs = ["utils_test.cc"],
    deps = [
        ":cc_library",
    ],
)

pl_cc_test(
    name = "binary_decoder_test",
    srcs = ["binary_decoder_test.cc"],
    deps = [
        ":cc_library",
    ],
)

pl_cc_test(
    name = "index_sorted_vector_test",
    srcs = ["index_sorted_vector_test.cc"],
    deps = [
        ":cc_library",
    ],
)

pl_cc_test(
    name = "linux_headers_test",
    srcs = ["linux_headers_test.cc"],
    data = [
        "testdata/config",
        "testdata/config.gz",
    ] + glob([
        "testdata/test_header_packages/*",
    ]),
    deps = [
        ":cc_library",
        "//src/common/system:cc_library",
    ],
)

pl_cc_test(
    name = "proc_tracker_test",
    srcs = ["proc_tracker_test.cc"],
    data = ["//src/common/system/testdata:proc_fs"],
    deps = [":cc_library"],
)

pl_cc_test(
    name = "obj_pool_test",
    srcs = ["obj_pool_test.cc"],
    deps = [":cc_library"],
)

pl_cc_test(
    name = "stat_counter_test",
    srcs = ["stat_counter_test.cc"],
    deps = [":cc_library"],
)

pl_cc_test(
    name = "enum_map_test",
    srcs = ["enum_map_test.cc"],
    deps = [":cc_library"],
)

pl_cc_test(
    name = "detect_application_test",
    srcs = ["detect_application_test.cc"],
    deps = [
        ":cc_library",
    ],
)

pl_cc_test(
    name = "monitor_test",
    srcs = ["monitor_test.cc"],
    deps = [
        ":cc_library",
        "//src/stirling/testing:cc_library",
    ],
)

pl_cc_bpf_test(
    name = "detect_application_bpf_test",
    timeout = "moderate",
    srcs = ["detect_application_bpf_test.cc"],
    tags = [
        "cpu:16",
        "requires_bpf",
    ],
    deps = [
        ":cc_library",
        "//src/stirling/source_connectors/socket_tracer/testing/container_images:node_14_18_1_alpine_container",
    ],
)

pl_cc_test(
    name = "run_core_stats_test",
    srcs = ["run_core_stats_test.cc"],
    deps = [
        ":cc_library",
        "//src/common/system:cc_library",
        "//src/stirling/testing:cc_library",
    ],
)
